home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c,comp.unix.programmer
- Path: phcoms4.seri.philips.nl!panther!baynes
- From: baynes@ukpsshp1.serigate.philips.nl (Stephen Baynes)
- Subject: Re: Q: '\n' character
- Sender: news@ukpsshp1.serigate.philips.nl (account for localnews)
- Message-ID: <DpBuF6.83C@ukpsshp1.serigate.philips.nl>
- Date: Thu, 4 Apr 1996 07:35:30 GMT
- References: <31616F63.481D@lava.weeg.uiowa.edu> <4jtddt$eu7@masala.cc.uh.edu>
- Organization: Philips Semiconductors, Southampton, UK
- X-Newsreader: TIN [version 1.2 PL2]
-
- Spasmo (cosc19z5@Bayou.UH.EDU) wrote:
- : Artur Wojdat (awojdat@lava.weeg.uiowa.edu) wrote:
- : : Hello everybody,
- : : Is there a function or some sort of way that I could remove '\n'
- : : charecter form the end of the string. I'm reading from two files, want to
- : Dunno if there are any functions available, but what I always do
- : is just overwrite the '\n' with a '\0', which does the job nicely.
-
- : For example, let's say that the string that holds the data is called
- : buf. To get rid of the '\n' you'd merely do the following:
-
- : buf[strlen(buf) - 1] = '\0';
-
- : And that takes care of that.
-
- Thats the best way, but do check that the character you are about to overwrite
- is a newline. There are two occasions when fgets stops without reading a
- newline, first if it has filled your buffer (because you have a very long line
- in the file), second if there is no newline at the end of the last line of the
- file.
-
- --
- Stephen Baynes baynes@ukpsshp1.serigate.philips.nl
- Philips Semiconductors Ltd
- Southampton My views are my own.
- United Kingdom
-